package com.fitness.front.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fitness.front.modal.coach.dto.CoachCommentDto;
import com.fitness.front.modal.coach.param.CoachCommentQueryParams;
import com.fitness.front.modal.coach.vo.CoachCommentVO;
import com.fitness.front.modal.response.ServerResponseEntity;
import com.fitness.front.service.ICoachCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/front/coach-comment")
public class CoachCommentController {

    private final ICoachCommentService coachCommentService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    public ServerResponseEntity<IPage<CoachCommentVO>> page(CoachCommentQueryParams queryParams) {
        Page<CoachCommentVO> result = coachCommentService.getCoachCommentPage(queryParams);
        return ServerResponseEntity.success(result);
    }

    /**
     * 新增
     * @param commentDto
     * @return
     */
    @PostMapping("/add")
    public ServerResponseEntity<Boolean> add(@RequestBody CoachCommentDto commentDto) {
        boolean result = coachCommentService.addCoachComment(commentDto);

        if(result) {
            return ServerResponseEntity.success();
        }
        return ServerResponseEntity.fail("CC10001","添加失败");
    }

    /**
     * 修改
     * @param commentDto
     * @return
     */
    @PutMapping("/update")
    public ServerResponseEntity<Boolean> update(@RequestBody CoachCommentDto commentDto) {
        boolean result = coachCommentService.updateCoachComment(commentDto);

        if(result) {
            return ServerResponseEntity.success();
        }
        return ServerResponseEntity.fail("CC10002","更新失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public ServerResponseEntity<Boolean> delete(@RequestBody Long id) {
        boolean result = coachCommentService.removeById(id);

        if(result) {
            return ServerResponseEntity.success(true);
        }
        return ServerResponseEntity.fail("C10003","删除失败");
    }
}
